<template>
	<div style="padding: 20px;">
		<transition name="custom-classes-transition" enter-active-class="animated fadeInDown" leave-active-class="animated fadeOutUp" >
			<addgrade :importeditid="editid" v-on:chance="chance"  v-if="show" style="margin-bottom: 20px;"><span>{{addoredit}}</span></addgrade>
		</transition>
		<Row>
	        <Col span="18" style="text-align: left;">
	        	<span>属性筛选：</span>
	        	<RadioGroup  v-model="noworhistorygrade" type="button" @on-change="changeselect">
	        		<Radio v-for="item in noworhistorygradelist" :key="item.value" :label="item.value">{{item.label}}</Radio>
			    </RadioGroup>
	        </Col>
	       
	    </Row>
		<Row>
			<Col span="12" style="text-align:left;">
	        	<span style="font-size: 18px;line-height: 32px;">年级列表:</span>
	        </Col>
	        <Col span="12" style="text-align:right;">
	        	<Button type="primary" icon="alicon alicon-up" @click="upgrade">一键升级</Button>
	        	<Button type="primary" icon="plus" @click="addgrade">添加年级</Button>
	        </Col>
	    </Row>
	    <div style="position: relative;">
		    <Collapse v-for="item in gradelist" :key="item.id" style="margin-top:15px;">
	            <Panel>		
	            	<span>{{item.grade}}</span>
	            	<span style="margin-left: 10%;">入学年份:{{item.year}}</span> 
	        		<Row >
				        <Col span="12">科目：{{item.subject}}</Col> 
				        <Col span="9" >
				        	<span>
				        		<span style="margin-left: 10px;">属性:{{item.branch}}</span>
				        	</span>
				        </Col>
				        <Col span="2">
			        		<Button type="ghost" shape="circle" icon="edit" @click.stop="editgrade(item.id)"></Button>
	        				<Button type="ghost" shape="circle" icon="trash-a" @click.stop="delgrade(item.id)"></Button>
				        </Col>
				    </Row> 
	                <div slot="content" > 
	                	<Row  style="margin-top:5px;" > 
	                		<Col span="2" offset="1">所有班级：</Col>
					        <Col v-for="items in item.allClasses" :key="items.classes" span="1" offset="1">{{items.classes}}班</Col> 
					    </Row><hr style="border: 1px solid #e9eaec;margin:5px;" />
	                </div>
	            </Panel>
		    </Collapse>
			<Spin size="large" fix v-if="loadingshow"></Spin> 
		</div> 
	</div>
</template>

<script>
	import addgrade from '@/components/performance/basicsetting/Addgrade'
	import api from "@/components/js/Apidomain.js"
	export default{
		data(){
			return{
				loadingshow:false,		//加载中的显示和隐藏
				show:false,				//添加年级的面板展现与关闭
				addoredit:"添加年级",
				
				
				noworhistorygrade:'1',	//往届或者在校
				editid:"",
				
				gradelist:"",
//				[
//					{id:"777777",grade:"高一年级",year:"2018",subject:"语文-数学-英语-历史-地理-生物-物理-化学-政治",branch:"不分文理科",allClasses:[{classes:"01"},{classes:"02"},{classes:"03"}]},
//					{id:"1111",grade:"高一年级",year:"2018",subject:"语文-数学-英语-历史-地理-生物-物理-化学-政治",branch:"不分文理科",allClasses:[{classes:"01"},{classes:"02"},{classes:"03"}]},
//					{id:"222",grade:"高一年级",year:"2018",subject:"语文-数学-英语-历史-地理-生物-物理-化学-政治",branch:"不分文理科",allClasses:[{classes:"01"},{classes:"02"},{classes:"03"}]},
//					{id:"333",grade:"高一年级",year:"2018",subject:"语文-数学-英语-历史-地理-生物-物理-化学-政治",branch:"不分文理科",allClasses:[{classes:"01"},{classes:"02"},{classes:"03"}]}
//				]
				noworhistorygradelist: [
					{value: '1',label: '在校'},
					{value: '2',label: '往届'},
                ],
			}
		},
		components:{
			addgrade,
		},
		created(){
			this.getgradelist();
		},
		methods:{
			changeselect:function(){
//				//console.log(this.branch)
//				//console.log(this.selectgrade);
				this.getgradelist();
			},
			addgrade:function(){
				this.addoredit = "新增年级信息"
				this.editid = "",
				this.show = true;
			},
			chance:function(){
				this.show = false;
				this.getgradelist();
			}, 
			editgrade:function(value){
				this.addoredit = "编辑年级信息"
				this.editid = value,
				this.show = true;
			},
			delgrade:function(value){
				this.$Modal.confirm({
                    title: '确定删除',
                    content: '<p>确定删除这一条年级信息吗</p>',
                    onOk: () => {
                        this.$Message.loading({
		                    content: '正在删除中',
		                    duration: 0
		                });
		                
		                //删除年级的接口
		                var self = this;
		            	let url = api.apidomain+'/tqes/web/tchGrade/deleteGrade';
		            	this.$http.post(url, {id:value}).then(function(response) {
							if(response.data.success == true){
								self.$Message.destroy();
								self.$Message.success({
				                    content: '删除成功',
				                    duration: 10,
				                    closable: true
		               			})
								self.getgradelist();
				            }else if(response.data.success == false){
				            		self.$Message.error({
										content: response.data.msg,
										duration: 10,
										closable: true
									});
				            	}
							})
							.catch(function(error) {
								self.$Message.error({
									content: '系统发生错误：错误码00024',
									duration: 10,
									closable: true
								});
							});
		                
		                
		                
                    },
                    onCancel: () => {
//                      this.$Message.info('Clicked cancel');
                    }
                });
			},
			getgradelist:function(){
				this.loadingshow = true;
				var self = this;
				if(this.noworhistorygrade == '1'){
					var url = api.apidomain+'/tqes/web/tchGrade/getGradeList';
				}
				if(this.noworhistorygrade == '2'){
					var url = api.apidomain+'/tqes/web/tchGrade/getGradeHistoryList';
				}
				
            	
            	this.$http.post(url, {}).then(function(response) {
					if(response.data.success == true){
						self.gradelist = response.data.data;
						self.loadingshow = false;
		            }else if(response.data.success == false){
		            		self.$Message.error({
								content: response.data.msg,
								duration: 10,
								closable: true
							});	
		            		self.loadingshow = false;
		            	}
					})
					.catch(function(error) {
						self.$Message.error({
							content: '系统发生错误：错误码00025',
							duration: 10,
							closable: true
						});
						self.loadingshow = false;
					});
			},
			upgrade:function(){
				this.$Modal.confirm({
                    title: '一键升级',
                    content: '<p>“一键升级”功能是把所有年级升一级，您确定要把所有年级升一级吗？</p>',
                    onOk: () => {
                        this.$Message.loading({
		                    content: '正在升级中',
		                    duration: 0
		                });
		                
		               
		                var self = this;
		            	let url = api.apidomain+'/tqes/web/tchGrade/oneKeyUpgradeGrade';
		            	this.$http.post(url,).then(function(response) {
							if(response.data.success == true){
								self.$Message.destroy();
								var showmsg = "";
								for(let i = 0;i<response.data.data.infoMsgs.length;i++){
									showmsg = showmsg + response.data.data.infoMsgs[i]+'<br>'
								}
//								//console.log(showmsg)
								self.$Modal.success({
		                            title: '升级成功',
		                            content: showmsg
//		                            content: response.data.data.infoMsgs
		                        });
//								self.$Message.success('升级成功');
								self.getgradelist();
				            }else if(response.data.success == false){
				            		self.$Message.destroy();
				            		self.$Message.error({
										content: response.data.msg,
										duration: 10,
										closable: true
									});	
				            	}
							})
							.catch(function(error) {
								self.$Message.destroy();
								self.$Message.error({
									content: '系统发生错误：错误码00026',
									duration: 10,
									closable: true
								});
							});
		                
		                
		                
                    },
                    onCancel: () => {
//                      this.$Message.info('Clicked cancel');
                    }
                });
			}
		}
	}
</script>

<style>
.ivu-collapse{
	text-align: left;	
}
.ivu-collapse-content>.ivu-collapse-content-box{
	padding:5px !important;
}
.ivu-collapse > .ivu-collapse-item > .ivu-collapse-header{
	height: auto !important;
}
.alicon-up{
	font-size: 15px !important;
}
</style>